fn main() {
    println!("-----------------------");
    test01_create();
    println!("-----------------------");
    test02_update();
    println!("-----------------------");
    test03_index();
    println!("-----------------------");
    test04_slice();
    println!("-----------------------");
    test05_traversal();
    println!("-----------------------");
}

fn test05_traversal() {
    for c in "Зд".chars() {
        print!("{c}");
    }
    println!();
    println!();

    for b in "Зд".bytes() {
        print!("{b} ");
    }
    println!();
}
fn test04_slice() {
    let hello = "Здравствуйте";
    println!("{hello}");

    let s = &hello[0..4];
    println!("{s}");

    //let s = &hello[0..1];//panic
    //println!("{s}");
}
fn test03_index() {
    //index is not supported

    let s1 = String::from("hi");
    println!("{s1}");
    //let h = s1[0];//err

    let hello = String::from("Hola"); //len=4
    println!("{hello}");
    let hello = String::from("Здравствуйте"); //len=24
    println!("{hello}");

    let hello = "Здравствуйте";
    println!("{hello}");
    //let answer = &hello[0];//err
}
fn test02_update() {
    let mut s = String::from("foo");
    println!("{s}");
    s.push_str("bar");
    println!("{s}");
    println!();

    let mut s1 = String::from("foo");
    let s2 = "bar";
    s1.push_str(s2);
    println!("s1 is {s1}");
    println!("s2 is {s2}");
    println!();

    let mut s = String::from("lo");
    s.push('l');
    println!("{s}");
    println!();

    let s1 = String::from("Hello, ");
    let s2 = String::from("world!");
    let s3 = s1 + &s2; // 注意 s1 被移动了，不能继续使用
    println!("{s3}");
    println!();

    let s1 = String::from("tic");
    let s2 = String::from("tac");
    let s3 = String::from("toe");

    let s = format!("{s1}-{s2}-{s3}");
}
fn test01_create() {
    let mut s = String::new();
    println!("{s}");
    let data = "initial contents";
    s = data.to_string();
    println!("{s}");

    let s = String::from("initial contents");
    println!("{s}");

    let hello = String::from("السلام عليكم");
    println!("{hello}");
    let hello = String::from("Dobrý den");
    println!("{hello}");
    let hello = String::from("Hello");
    println!("{hello}");
    let hello = String::from("שלום");
    println!("{hello}");
    let hello = String::from("नमस्ते");
    println!("{hello}");
    let hello = String::from("こんにちは");
    println!("{hello}");
    let hello = String::from("안녕하세요");
    println!("{hello}");
    let hello = String::from("你好");
    println!("{hello}");
    let hello = String::from("Olá");
    println!("{hello}");
    let hello = String::from("Здравствуйте");
    println!("{hello}");
    let hello = String::from("Hola");
    println!("{hello}");
}
